import { createRouter, createWebHistory } from 'vue-router'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: "/",
      redirect: "/login"
    },
    {
      path: "/login",
      component: () => import("../pages/login/Index.vue")
    },
    {
      path: "/home",
      component: () => import("../pages/home/Index.vue"),
      meta: {
        required: true
      },
      children: [
        {
          path: "/home",
          redirect: "/home/index"
        },
        {
          path: "/home/index",
          component: () => import("../pages/home/index/Index.vue"),
        },
        {
          path: "/home/banner",
          component: () => import("../pages/home/banner/Index.vue"),
        },
        {
          path: "/home/type",
          component: () => import("../pages/home/type/Index.vue"),
        },
        {
          path: "/home/product",
          component: () => import("../pages/home/product/Index.vue"),
        },
        {
          path: "/home/sale",
          component: () => import("../pages/home/sale/Index.vue"),
        },
        {
          path: "/home/user",
          component: () => import("../pages/home/user/Index.vue"),
        },
        {
          path: "/home/map",
          component: () => import("../pages/home/map/Index.vue"),
        },
      ]
    },
    { 
      path: '/:pathMatch(.*)*',
      component: () => import("../pages/notfound/Index.vue")
    },
  ],
})

// router.beforeEach((to, from, next) => {
//   if (to.meta.required) {
//     if (localStorage.getItem("token")) {
//       next()
//     } else {
//       next("/login")
//     }
//   } else {
//     next()
//   }
// })

export default router
